package com.zyf.chapter01.principle.SOLID.LSP;

import com.zyf.chapter01.principle.SOLID.LSP.utils.HttpClient;
import com.zyf.chapter01.principle.SOLID.LSP.utils.Request;
import com.zyf.chapter01.principle.SOLID.LSP.utils.Response;
import com.zyf.chapter01.principle.SOLID.LSP.utils.StringUtils;

/**
 * 支持安全认证的网络传输类
 * @author yifeng
 */
public class SecurityTransporter extends Transporter {

    private String appId;
    private String appToken;

    public SecurityTransporter(HttpClient httpClient, String appId, String appToken) {
        super(httpClient);
        this.appId = appId;
        this.appToken = appToken;
    }

    @Override
    public Response sendRequest(Request request) {
        if (StringUtils.isNotBlank(appId) && StringUtils.isNotBlank(appToken)) {
            request.addPayload("app-id", appId);
            request.addPayload("app-token", appToken);
        }
        return super.sendRequest(request);
    }
}
